<?php
/**
 * Created by Maxotm.
 * User: tuyt
 * Date: 2019/5/23
 */

namespace App\Http\ViewComposers;

use App\Models\Article;
use App\Models\Category;
use App\Models\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;

class SidebarComposer
{
    public function compose(View $view)
    {
        //获取点击排行
        $topArticles =( new Article())->getTop();
        $tags = (new Tag())->getTags();
        $siteInfo = DB::table('site')->first();
        $totalArticle =  array_sum( Category::pluck('post_count')->toArray());

        $view->with([
            'topArticles'=>$topArticles,
            'tags'=>$tags,
            'siteInfo'=>$siteInfo,
            'totalArticle'=>$totalArticle,
        ]);
    }
}